package com.huan.vertxle.verticle;

import com.huan.vertxle.enums.EventBusBusinessEnum;
import com.huan.vertxle.service.IScanCodeService;
import com.huan.vertxle.service.impl.ScanCodeServiceImpl;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.Slf4JLoggerFactory;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;

/**
 * 扫描模块业务
 */
public class ScanCodeVerticle extends AbstractVerticle {
  private final InternalLogger logger = Slf4JLoggerFactory.getInstance(this.getClass());

  private final IScanCodeService scanCodeService;

  public ScanCodeVerticle() {
    scanCodeService = new ScanCodeServiceImpl();
  }

  @Override
  public void start() throws Exception {
    EventBus eventBus = vertx.eventBus();
    eventBus.<String>consumer(EventBusBusinessEnum.BUSINESS_SCAN.name(), msg -> {
      String body = msg.body();
      logger.info("eventBus接收到消息:{}", body);
      scanCodeService.dealScanData(body, msg);
    });
    logger.info("扫描业务模块启动");
  }
}
